package cn.intotw; /**
 * Created by Chenxiang
 *
 * @generator: IntelliJ IDEA
 * @description:
 * @project: rdcj
 * @package: PACKAGE_NAME
 * @date: 2021年02月25日 14时03分
 * <p>
 * 比较字符串直接相加和StringBuilder的效率
 * @author XiongNeng
 * @version 1.0
 * @since 2018/1/7
 */

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.SampleTime)
@Warmup(iterations = 3)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(1)
@Fork(2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class StringBuilderBenchmark {

    @Benchmark
    public void testBigLoopOutSide() {
        long k = 0;
        for (int j = 0; j < 1000000000; j++) {
            for (int i = 0; i < 100; i++) {
                k++;
            }
        }
        use(k);
    }
    void use(long k){

    }
    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(StringBuilderBenchmark.class.getSimpleName())
                .output("D:/Benchmark.log")
                .build();
        new Runner(options).run();
    }
}